package com.gdut.simple.model.impl;

import com.gdut.simple.common.RequestCallback;
import com.gdut.simple.data.entity.User;
import com.gdut.simple.model.IFollowUserModel;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.datatype.BmobPointer;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class FollowUserModelImpl implements IFollowUserModel {

    @Override
    public void getFollowList(User user, int page, final RequestCallback<List<User>> callback) {
        BmobQuery<User> query = new BmobQuery<>();
        query.addWhereRelatedTo("follow", new BmobPointer(user));
        query.setSkip(10 * (page - 1));
        query.include("user");
        query.findObjects(new FindListener<User>() {
            @Override
            public void done(List<User> list, BmobException e) {
                if (e == null) {
                    if (callback != null) {
                        callback.onSuccess(list);
                    }
                } else {
                    if (callback != null) {
                        callback.onFailure(e.getMessage());
                    }
                }
            }
        });
    }
}
